<template>
  <div class="luotong_r">
    <a-tooltip :mouseEnterDelay="1" placement="top">
      <div slot="title">
        <span class="content_title">设备编号：</span>
        {{ tooltipData.deviceNo }}
        <br />
        <span class="content_title">设备状态：</span>
        {{ getHeadName(tooltipData.status) }}
        <br />
        <span class="content_title">设备效率：</span>
        {{ Number(tooltipData.efficiency * 100).toFixed(2) }}%
        <br />
        <span class="content_title">生产品种：</span>
        <!-- R40SAA-1 -->
        {{ tooltipData.productTypeTxt }}
        <br />
        <span class="content_title">更新时间：{{ $moment(tooltipData.updateTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
      </div>
      <svg
        width="92px"
        height="14px"
        viewBox="0 0 92 14"
        version="1.1"
        xmlns="http://www.w3.org/2000/svg"
        xmlns:xlink="http://www.w3.org/1999/xlink"
      >
        <defs>
          <pattern id="jhtt" width="7" height="20">
            <image
              width="7"
              height="20"
              stroke="black"
              viewBox="0 0 7 20"
              xlink:href="~@/assets/img/chart/status/status6-footer.png"
              preserveAspectRatio="none"
            />
          </pattern>
        </defs>
        <g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
          <g id="立华平面图" transform="translate(-176.000000, -160.000000)">
            <g id="编组-47" transform="translate(15.000000, 55.000000)">
              <g id="编组-40" transform="translate(12.000000, 15.000000)">
                <g id="编组-32" transform="translate(150.000000, 0.000000)">
                  <g id="编组-31" transform="translate(0.000000, 73.000000)">
                    <g id="编组-7" transform="translate(0.000000, 17.000000)">
                      <g
                        id="编组-43"
                        transform="translate(45.000000, 7.000000) rotate(-90.000000) translate(-45.000000, -7.000000) translate(40.500000, -38.000000)"
                        fill="#2D69C7"
                        stroke="#8FCDFA"
                      >
                        <polygon
                          id="矩形"
                          points="0 11 7 11 7 14.5 9 14.5 9 19.6114918 7 19.6114918 7 81 0 81"
                          :style="bodyStyle"
                        ></polygon>
                        <path
                          d="M3.5,0 C5.43299662,-3.55085719e-16 7,1.56700338 7,3.5 L7,11 L7,11 L0,11 L0,3.5 C-2.36723813e-16,1.56700338 1.56700338,3.55085719e-16 3.5,0 Z"
                          id="矩形"
                          :style="headStyle"
                        ></path>
                        <rect
                          id="矩形备份-4"
                          transform="translate(3.500000, 85.000000) scale(1, -1) translate(-3.500000, -85.000000) "
                          x="0"
                          y="80"
                          width="7"
                          height="10"
                          rx="1"
                          :style="bodyStyle"
                        ></rect>
                      </g>
                      <text
                        id="2"
                        font-family="PingFangSC-Medium, PingFang SC"
                        font-size="10"
                        font-weight="400"
                        fill="#FFFFFF"
                      >
                        <tspan x="39.5" y="11">{{ tooltipData.deviceNo }}</tspan>
                      </text>
                    </g>
                  </g>
                </g>
              </g>
            </g>
          </g>
        </g>
      </svg>
    </a-tooltip>
  </div>
</template>

<script>
import { mul } from '@/utils/caculate'
export default {
  name: 'luotong_r',
  props: {
    data: Object,
    // 是否嵌套在弹窗内
    inline: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      headStyle: {
        fill: ''
      },
      bodyStyle: {
        fill: ''
      },
      tooltipData: {
        deviceNo: 0,
        deviceName: null,
        efficiency: 0,
        productType: null,
        productTypeTxt: null,
        status: 0,
        updateTime: null
      }
    }
  },

  watch: {
    data: {
      deep: true, //true 深度监听
      immediate: true,
      handler() {
        this.draw()
      }
    }
  },

  mounted() {
    this.draw()
  },
  methods: {
    draw() {
      if (this.data) {
        this.tooltipData = { ...this.data }
        this.headStyle.fill = this.getHeadColor(this.tooltipData.status)
        this.bodyStyle.fill = this.getBodyColor(this.tooltipData.efficiency)
      }
    },
    //尾灯表示车台状态（运行、停止、故障、满纱满桶、通讯失败)
    getHeadColor(status) {
      switch (parseInt(status)) {
        //运行
        case 1:
          return '#7CBC44'
        //停止
        case 2:
          return '#888F93'
        //故障
        case 3:
          return '#6D000E'
        //满纱满桶
        case 4:
          return '#ECCD54'
        //通讯失败
        case 5:
          return '#EB4E27'
        // 计划停台
        case 6:
          return 'url(#jhttbt)'
      }
    },
    //尾灯表示车台状态（运行、停止、故障、满纱满桶、通讯失败)
    getHeadName(status) {
      switch (parseInt(status)) {
        //运行
        case 1:
          return '运行'
        //停止
        case 2:
          return '停止'
        //故障
        case 3:
          return '故障'
        //满纱满桶
        case 4:
          return '满纱满桶'
        //通讯失败
        case 5:
          return '通讯失败'
        // 计划停台
        case 6:
          return '计划停台'
      }
    },
    //车身颜色渐变表示车台当前效率范围
    getBodyColor(stateCode1) {
      let stateCode = Number(stateCode1) * 100
      if (stateCode >= 90) {
        return '#2D69C7'
      } else if (90 > stateCode && stateCode >= 80) {
        return '#ECCD54'
      } else if (80 > stateCode && stateCode > 70) {
        return '#ECCD54'
      } else if (stateCode <= 70) {
        return '#EB4E27'
      }
    }
  }
}
</script>

<style lang="less" scoped>
@import '~@/assets/less/workshop.less';
.cls-1 {
  fill: #519aff;
}

.cls-1,
.cls-2,
.cls-4 {
  stroke: #82c4fa;
  stroke-width: 10px;
}

.cls-2 {
  fill-rule: evenodd;
  fill: url(#linear-gradient);
}

.cls-3 {
  fill: #fff;
  font-family: 'Source Han Sans CN';
  font-weight: 700;
  word-break: break-all;
}

.cls-4 {
  fill: url(#linear-gradient-2);
}

.luotong_r {
  width: 92px;
  margin-left: auto;
}
</style>
